#ifdef KITSCHY_DEBUG_MEMORY 
#include "debug_memorymanager.h"
#endif

#include "stdio.h"
#include "stdlib.h"
#include "string.h"

#include "BList.h"

#include "symbol.h"

#include "AWMessage.h"


AW_Message::AW_Message(Symbol *sndr,Symbol *rcvr,Symbol *ct,float t) 
{
	if (sndr==0) sender=0;
			else sender=new Symbol(sndr);
	receiver=new Symbol(rcvr);
	content=new Symbol(ct);
	time=t;
} /* AW_Message::AW_Message */ 


AW_Message::AW_Message(Symbol *sndr,Symbol *rcvr,Symbol *ct) 
{
	if (sndr==0) sender=0;
			else sender=new Symbol(sndr);
	receiver=new Symbol(rcvr);
	content=new Symbol(ct);
	time=0;
} /* AW_Message::AW_Message */ 


AW_Message::AW_Message(AW_Message &msg) 
{
	if (msg.sender==0) sender=0;
				  else sender=new Symbol(msg.sender);
	receiver=new Symbol(msg.receiver);
	content=new Symbol(msg.content);
	time=msg.time;
} /* AW_Message::AW_Message */ 


AW_Message::AW_Message(FILE *fp)
{
	sender=receiver=content=0;
	time=0;
	load(fp);
} /* AW_Message::AW_MEssage */ 


AW_Message::~AW_Message()
{
	if (sender!=0) delete sender;
	sender=0;
	delete receiver;
	receiver=0;
	delete content;
	content=0;
} /* AW_Message::AW_MEssage */ 



bool AW_Message::load(FILE *fp)
{
	sender=new Symbol(fp);
	receiver=new Symbol(fp);
	content=new Symbol(fp);
	if (sender==0 || receiver==0 || content==0) return false;
	if (1!=fscanf(fp,"%f",&time)) return false;

	return true;
} /* AW_Message:load */ 



bool AW_Message::save(FILE *fp)
{

	if (!sender->save(fp)) return false;
	if (!receiver->save(fp)) return false;
	if (!content->save(fp)) return false;
	fprintf(fp,"%f\n",time);

	return true;
} /* AW_Message:save */ 

